/**
 * CopyRight © 2012 USTC SINOVATE SOFTWARE CO.LTD All Rights Reserved.
 */

package com.cmcc.zysoft.infocollection.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
import com.cmcc.zysoft.infocollection.model.Role;
import com.starit.common.dao.hibernate.HibernateBaseDaoImpl;

/**
 * @author 袁凤建
 * <br />邮箱: yuan.fengjian@ustcinfo.com
 * <br />描述: RolePcDao.java
 * <br />版本: 1.0.0
 * <br />日期: 2013-9-6 上午9:42:57
 * <br />CopyRight © 2012 USTC SINOVATE SOFTWARE CO.LTD All Rights Reserved.
 */

@Repository
public class RolePcDao extends HibernateBaseDaoImpl<Role, String> {

	@Autowired
	private JdbcTemplate jdbcTemplate;
	
	/**
	 * 获取角色分页列表信息.
	 * @param page
	 * @param rows
	 * @return map
	 */
	public Map<String, Object> roles(int page, int rows) {
		int offset = (page - 1) * rows;
		Map<String, Object> map = new HashMap<String, Object>();
		String rowSql = 
				" SELECT a.role_id AS roleId, a.company_id AS companyId, a.role_name AS roleName, a.description AS description, " +
				" 		 a.role_code AS roleCode, a.status AS 'status', a.display_order AS displayOrder " +
				" FROM tb_c_role a, tb_c_dict_type b, tb_c_dict_data c " +
				" WHERE a.role_code = c.data_code AND b.type_id = c.type_id AND b.type_code = 'role' " +
				" ORDER BY a.role_code, a.display_order LIMIT ?, ? ";
		String countSql = 
				" SELECT COUNT(*) " +
				" FROM tb_c_role a, tb_c_dict_type b, tb_c_dict_data c " +
				" WHERE a.role_code = c.data_code AND b.type_id = c.type_id AND b.type_code = 'role' ";
		List<Map<String, Object>> list = this.jdbcTemplate.queryForList(rowSql, offset, rows);
		int total = this.jdbcTemplate.queryForInt(countSql);
		map.put("rows", list);
		map.put("total", total);
		return map;
	}
	
	/**
	 * 获取信息采集员的角色ID.
	 * @return List<Map<String, Object>>
	 */
	public List<Map<String, Object>> getCollectorRoleId() {
		String sql = " SELECT a.* FROM tb_c_role a WHERE a.role_code = '2' AND a.status = '0' ";
		return this.jdbcTemplate.queryForList(sql);
	}
}